<?php

session_start();
if(!isset($_SESSION['userId']))
{
	header("location:index.php");
}
include("../class/config.php");
include("../class/cls_inquiry.php");

if(isset($_POST['add']))
{
	$inq_name=$_POST['inquiry_name'];
	$inq_org=$_POST['inquiry_org'];
	$inq_email=$_POST['inquiry_email'];
	$inq_address=$_POST['inquiry_address'];
	$inq_phone=$_POST['inquiry_phone'];
	$inq_apply=$_POST['inquiry_apply'];
	$inq_msg=$_POST['inquiry_msg'];
	$date=date("Y-m-d H:i:s");
	$objInquiry->addInquiry($inq_name,$inq_org,$inq_email,$inq_address,$inq_phone,$inq_apply,$inq_msg,$date);
	$success="Inquiry added successfully.";
}
if(isset($_GET['deleteId']))
{
	$InqId=$_GET['deleteId'];
	$objInquiry->deleteInquiry($InqId);
	}
if(isset($_GET['editId']))
{
	$catid=$_GET['editId'];
		if(isset($_POST['edit']))
			{
				$catName=$_POST['category_name'];
				$cat_details=$_POST['category_details'];
				$catDate=date("Y-m-d h:i:s");
				$objCategory->editCategory($catid,$catName,$cat_details,$catDate);
				
			}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Category</title>
<script type="text/javascript" src="../lib/frmValidation.js">
</script>
<link rel="stylesheet" href="../css/layout.css" />
</head>
<body>

	<div class="mainWrapper">
     <?php include("../includes/adminHeader.php");?>
    
    <div class="bodyContent">
    <h1>Inquiry</h1>
    <div class="innerBody">
    <?php if(!isset($_GET['action']))
	{?>
    <strong>Inquiry Listing</strong>  | <a href="?action=add">Add Inquiry</a>
     
	
      <table width="100%" border="0" cellpadding="1" cellspacing="1" class="table">
        <tr>
          <th>Sn</th>
          <th>Inquiry Added Date</th>
          <th>Inquiry Name</th>
          <th>Organization</th>
          <th>Email</th>
          <th>Address</th>
          <th>Phone</th>
          <th>Applyed For</th>
          <th>Message</th>
          <th>Action</th>
        </tr>
		<?php $resInquiry= $objInquiry->selectInquiry();
		$i=1;
		
		while($recInquiry=mysqli_fetch_array($resInquiry))
		{
		?>
        <tr>
          <td><?php echo $i++;?></td>
          <td><?php echo $recInquiry['inquiry_added_date'];?></td>
          <td><?php echo $recInquiry['inquiry_name'];?></td>
          <td><?php echo $recInquiry['inquiry_org'];?></td>
          <td><?php echo $recInquiry['inquiry_email'];?></td>
          <td><?php echo $recInquiry['inquiry_address'];?></td>
          <td><?php echo $recInquiry['inquiry_phn'];?></td>
          <td><?php echo $recInquiry['inquiry_apply'];?></td>
          <td><?php echo $recInquiry['inquiry_msg'];?></td>
		  
          <td><a href="?action=edit&editId=<?php echo $recInquiry['inquiry_id'];?>">Edit</a> | <a href="?deleteId=<?php echo $recInquiry['inquiry_id'];?>" onclick="javascript:return confirm('Are You Sure You Want to Delete this Record?')">Delete</a></td>
        </tr>
        <?php } /// end of while($recCategory=mysqli_fetch_array($resCategory))
?>
       </table>
       
     <?php }
	 else if(isset($_GET['action']) && $_GET['action']=='edit')
	 {
		 $catId=$_GET['editId'];
		 $res=$objCategory->getCategoryById($catId);
		 $rec=mysqli_fetch_array($res);
	 
	 ?>
      <strong>Edit Category</strong>
      <form id="categoryEdit" name="categoryEdit" method="post" action="" onsubmit="return editCat()">
        <table width="100%" border="0" class="table" cellpadding="1" cellspacing="1">
          <tr>
            <td width="30%">Category Name *</td>
            <td><input type="text" name="category_name" id="category_name" class="textBox" value="<?php echo $rec['cat_name'];?>" /></td>
          </tr>
          <tr>
            <td width="30%">Category Details *</td>
            <td><input type="text" name="category_details" id="category_details" class="textBox" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input type="submit" name="edit" id="edit" value="Edit" />
            	<input type="button" name="cancel" value="cancel" onclick="javascript:location.href='category.php'" /></td>
          </tr>
          <tr>
            <td>Note : * Fields are mandatory.</td>
            <td>&nbsp;</td>
          </tr>
        </table>
      </form>
 <?php }
	 else if(isset($_GET['action']) && $_GET['action']=='add')
	 {
	 
	 ?>
      <strong>Add Category</strong>
      <?php 
	  if(isset($success))
      {
      echo $success;
      } ?>
      <form id="addCategory" name="addCategory" method="post" action="" onsubmit="return addCat()">
        <table width="100%" border="0" class="table" cellpadding="1" cellspacing="1">
          <tr>
            <td width="30%">Inquiry Name *</td>
            <td><input type="text" name="inquiry_name" id="inquiry_name" class="textBox" /></td>
          </tr>
          <tr>
            <td width="30%">Inquiry Organization *</td>
            <td><input type="text" name="inquiry_org" id="inquiry_org" class="textBox" /></td>
          </tr>
          <tr>
            <td width="30%">Inquiry Email *</td>
            <td><input type="text" name="inquiry_email" id="inquiry_email" class="textBox" /></td>
          </tr>
          <tr>
            <td width="30%">Inquiry Address *</td>
            <td><input type="text" name="inquiry_address" id="inquiry_address" class="textBox" /></td>
          </tr>
          <tr>
            <td width="30%">Inquiry Phone *</td>
            <td><input type="text" name="inquiry_phone" id="inquiry_phone" class="textBox" /></td>
          </tr>
          <tr>
            <td width="30%">Inquiry Applying For *</td>
            <td><input type="text" name="inquiry_apply" id="inquiry_apply" class="textBox" /></td>
          </tr>
          <tr>
            <td width="30%">Inquiry Message *</td>
            <td><textarea rows="5" cols="50" name="inquiry_msg" id="inquiry_msg" class="textBox" /></textarea></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input type="submit" name="add" id="add" value="Add"  />
            	<input type="button" name="cancel" value="cancel" onclick="javascript:location.href='inquiry.php'" /></td>
          </tr>
          <tr>
            <td>Note : * Fields are mandatory.</td>
            <td>&nbsp;</td>
          </tr>
        </table>
      </form>
<?php }?>
    </div>
    
    </div>
    
    
    <?php include("../includes/adminFooter.php");?>
     
       </div>

</body>
</html>